from pydantic import BaseModel, Field, validator, EmailStr
from typing import Union
from tortoise.contrib.pydantic import pydantic_model_creator
from core.validation_rules.fieldRules import StringRules

from models.user import ZhanUser


class User(BaseModel):
    id: int
    username: str
    login_type: int
    status: int
    phone: Union[str, None] = None


class Token(BaseModel):
    access_token: str
    token_type: str


class UserRegister(BaseModel):
    username: str = Field(min_length=3, max_length=128)
    password: str = Field(min_length=6, max_length=128)
    code: str = Field(min_length=6)


class EmailVerify(BaseModel):
    email: str

    @validator("email")
    @StringRules.emailRule
    def check_email(cls, column):
        return column


class FeedBack(BaseModel):
    email: str
    app_bug: str
    suggest: str

    @validator("email")
    @StringRules.emailRule
    def check_email(cls, column):
        return column


class ForgotPasswordRequest(BaseModel):
    email: EmailStr
    code: str
    password: str


zhanuser_pydantic_model = pydantic_model_creator(ZhanUser, exclude=("password",))
